﻿namespace CryptoQrUtilities.Cryption
{
    /// <summary>
    /// An immutable implementation for a decryptor/encryptor that expects one public key encrypting the AES key.
    /// </summary>
    internal class SingleKeyDencryptor : IMessageDencrypter
    {
        /// <summary>
        /// Create a new instance of <see cref="SingleKeyDencryptor"/> initializing .NET RSA container parameters.
        /// </summary>
        /// <param name="rsaProvider">The RSA provider to use with this dencryptor.</param>
        public SingleKeyDencryptor(IRsaProvider rsaProvider)
        {
            RsaProvider = rsaProvider;
        }

        #region IMessageDecryptor implementation

        public virtual string DecryptMessage(QrMessage message)
        {
            var envelope = new CryptedEnvelope(message.MessageContents, false);

            return envelope.RetrieveEnvelopeContents(RsaProvider);
        }

        #endregion

        /// <summary>
        /// Gets the RSA provider associated with this Dencryptor.
        /// </summary>
        public IRsaProvider RsaProvider { get; private set; }
    }
}
